package cn.com.demo.microservice.consumer.controller;

import cn.com.demo.microservice.consumer.service.IUserService;
import cn.com.demo.microservice.reps.ResponseObject;
import cn.com.demo.microservice.vo.Account;
import cn.com.demo.microservice.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;
    @PostMapping("/create")
    public ResponseObject createUser(@RequestBody User user){
        ResponseObject result = new ResponseObject();
        user = this.userService.addUser(user);
        if(user != null){
            Map<String,Integer> map = new HashMap<String, Integer>();
            map.put("urId", user.getUrId());
            List<Account> accountList = user.getAccountList();
            if(accountList != null && accountList.size()>0){
                Account account = accountList.get(0);
                map.put("accId", account.getId());
            }
            result.setData(map);
        }
        return result;
    }
}
